//============================================================================
// Name        : xLiveServer.cpp
// Author      : longwuwei
// Version     :
// Copyright   : copyright @ 2013
// Description : Hello World in C++, Ansi-style
//============================================================================

#include "Mediaservice.h"

/**
 * server run flag
 */
using namespace std;
volatile sig_atomic_t _running = 1;
void sigterm_handler(int arg)
{
	_running = 0;
}

int main() {

	/*
	 * run as net backrgound server
	 * */
	daemon(1, 0);

	/*
	*receive control signal
	*/
	signal(SIGTERM, sigterm_handler);

	/**
	 * init server and start run sevedr
	 */
    Mediaservice svr;
    if(svr.Svr_Start() != SUCCESS)
    {
        svr.Svr_Stop();
        return 0;
    }
    else
    {
        cout << "media service start success!" <<endl;
    }

    /**
     * run
     */
    while(svr.Svr_Status() && _running == 1)
    {
        svr.Svr_Run(100000);

        usleep(100000);
    }
    /**
     * svr stoping
     */
    svr.Svr_Stop();
    usleep(1000000);

    /*
	 * exit proc
	 */
    return 0;
}
